package com.vogue.supplymall.order.interceptor;

import com.vogue.supplymall.common.domain.dto.UserInfo;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * The type Order interceptor.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-01-10
 */
public class OrderInterceptor implements HandlerInterceptor {
    
    public static final Logger LOGGER_ORDERINTERCEPTOR = LoggerFactory.getLogger(OrderInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        LOGGER_ORDERINTERCEPTOR.info("controller 前处理拦截");
        if (SecurityUtils.getSubject().isAuthenticated()) {
            UserInfo info = (UserInfo) SecurityUtils.getSubject().getPrincipal();
            LOGGER_ORDERINTERCEPTOR.info("登录人：" + info.getLoginId());
        } else {
            LOGGER_ORDERINTERCEPTOR.info("未登录");
            return true;
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
